package lacus.wd_cinema.controller.api;

import jakarta.servlet.http.HttpServletRequest;
import lacus.wd_cinema.dto.screenings.ScreeningAddRequest;
import lacus.wd_cinema.dto.screenings.ScreeningAddResponse;
import lacus.wd_cinema.entity.User;
import lacus.wd_cinema.service.AuthService;
import lacus.wd_cinema.service.ScreeningService;
import org.springframework.web.bind.annotation.*;

/**
 * 放映接口控制类
 * @author lacus
 * @version 0.5
 * @since 0.4
 */
@RestController
@RequestMapping("/api/screenings")
public class ScreeningController {
    private final ScreeningService screeningService;
    private final AuthService authService;

    public ScreeningController(ScreeningService screeningService, AuthService authService) {
        this.screeningService = screeningService;
        this.authService = authService;
    }

    /** 添加新的放映 */
    @PostMapping
    public ScreeningAddResponse addScreening(
            @RequestBody ScreeningAddRequest screeningAddRequest,
            HttpServletRequest servletRequest) {
        User operator = authService.getCurrentUser(servletRequest);
        return screeningService.addScreening(screeningAddRequest ,operator);
    }

    /** 删除已添加的放映 */
    @DeleteMapping("/{id}")
    public void deleteScreening(
            @PathVariable String id,
            HttpServletRequest servletRequest) {
        User operator = authService.getCurrentUser(servletRequest);
        screeningService.deleteScreening(id, operator);
    }

    /** 使放映对外开放售票 */
    @PostMapping("/{id}/open-for-sale")
    public void openForSale(
            @PathVariable String id,
            HttpServletRequest servletRequest) {
        User operator = authService.getCurrentUser(servletRequest);
        screeningService.openForSale(id, operator);
    }
}
